package constants

import (
	"fmt"
	"time"
)

// log time format
const (
	None                 = 0
	LogTimeFormat        = "2006/01/02 15:04:05.000"
	RedisDateTime        = "20060102"
	DigitDateTimeFormat  = "20060102-150405"
	DayDuration          = 86400
	Two                  = 2
	TwoDayDuration       = Two * DayDuration
	ThreeDayDuration     = 3 * DayDuration
	TenDayDuration       = 10 * DayDuration
	SevenDayDuration     = 7 * DayDuration
	Sixty                = 60
	SixtyDayDuration     = Sixty * DayDuration
	HourDuration         = 3600
	TwelveHourDuration   = 12 * HourDuration
	HourDurationMs       = 3600000
	OneSecondMs          = 1000
	Thirty               = 30
	ThirtySeconds        = 30
	OneMinutes           = 60
	OneMinuteDuration    = 60 * time.Second
	TwoMinutes           = 2 * OneMinutes
	FiveMinutes          = 5 * OneMinutes
	FiveMinutesMs        = FiveMinutes * OneSecondMs
	ValidTimeMs          = 1000000000000
	ThirtyDaysSeconds    = 30 * 24 * 3600
	ThirtyOneDaysSeconds = 31 * 24 * 3600
	HalfHourSeconds      = 1800 // 30分钟
	MaxSqsDelaySeconds   = 900  // sqs最大延迟时间(秒)
)

// app name
const (
	EufyCare     = "eufy_care"
	EufySecurity = "eufy_security"
	EufyMega     = "eufy_mega"
)

// app name uid prefix
const (
	EufyCarePrefix        = "care"
	EufyCareVirtualPrefix = "T83"
)

// service name
const (
	TagZxService = "zxservice"
	TagMoat      = "moat"
	TagChaos     = "chaos"
	TagBoat      = "boat"
	TagSmart     = "smart"
)

// tag name
const (
	TagMain      = "main"
	TagStat      = "stats"
	TagRecovery  = "recovery"
	TagFramework = "framework"
	TagHelper    = "helper"
	TagAdmin     = "admin"
	TagConfig    = "config"
	TagCronTask  = "crontask"

	TagPrefixOrders = "PrefixOrders"
)

const (
	MAX_LOGIN_ERR_PRIFX_KEY = "MOAT:LOGIN_ERR_MAX:"
	MAX_LOGIN_PRIFX_KEY     = "MOAT:LOGIN_MAX:"

	MAX_LOGIN_ERR_PRIFX_KEY_V2 = "MOAT:LOGIN_ERR_MAX_V2:"
	MAX_LOGIN_PRIFX_KEY_V2     = "MOAT:LOGIN_MAX_V2:"

	MAX_REGISTER_PREFIX_KEY = "MOAT:REGISTER_MAX:"
	MAX_FORGET_PASSWORD_KEY = "MOAT:FORGET_PASSWORD_MAX:"
)

// privilege
const (
	PrivilegeNone         = 0
	PrivilegeServerSwitch = 1
)

// param name
const (
	ParamID                 = "id"
	ParamIDs                = "ids"
	ParamPage               = "page"
	ParamNum                = "num"
	ParamOrderBy            = "orderBy"
	ParamBeginTime          = "begin_time"
	ParamOffTime            = "off_time"
	ParamUserID             = "user_id"
	ParamStationSn          = "station_sn"
	ParamDeviceSn           = "device_sn"
	ParamFavorite           = "favorite"
	ParamMonitorID          = "monitor_id"
	ParamPackageNo          = "package_no"
	ParamOrderNo            = "order_no"
	ParamStatus             = "status"
	ParamEmail              = "email"
	ParamStartTime          = "start_time"
	ParamEndTime            = "end_time"
	ParamActionID           = "action_id"
	ParamActionSubID        = "action_sub_id"
	ParamActionUserID       = "action_user_id"
	ParamModel              = "model"
	ParamVersion            = "version"
	ParamFileSn             = "file_sn"
	ParamFileType           = "file_type"
	ParamTimePoint          = "tp"
	ParamBody               = "body"
	ParamUserName           = "UserName"
	ParamSiteURL            = "SiteUrl"
	ParamAdminName          = "AdminName"
	ParamAdminEmail         = "AdminEmail"
	ParamUserEmail          = "UserEmail"
	ParamDateTime           = "DateTime"
	ParamSn                 = "Sn"
	ParamLogo               = "Logo"
	ParamBanner             = "Banner"
	ParamAppStore           = "AppStore"
	ParamGooglePlay         = "GooglePlay"
	ParamVerifyCode         = "VerifyCode"
	ParamVerificationCode   = "VerificationCode"
	ParamComment            = "Comment"
	DefaultLogoKey          = "/overall/images/logo.png"
	DefaultBannerKey        = "/overall/images/banner.jpg"
	DefaultAppStoreKey      = "/overall/images/app_store.png"
	DefaultGooglePlayKey    = "/overall/images/google_play.png"
	ParamCode               = "code"
	ParamP2PDid             = "p2p_did"
	ParamRecreate           = "recreate"
	ParamTemorary           = "temporary"
	ParamDskKey             = "dsk_key"
	ParamMessage            = "message"
	ParamToken              = "token"
	ParamExpireAt           = "expire_at"
	ParamKeyTtl             = "key_ttl"
	ParamPath               = "path"
	ParamEventType          = "event_type"
	ParamOpenudid           = "Openudid"
	ParamOsType             = "Os_type"
	ParamOsVersion          = "Os_version"
	ParamAppVersion         = "App_version"
	ParamGToken             = "gtoken"
	ParamRequestParam       = "request_param"
	ParamResponseParam      = "response_param"
	ParamHeader             = "header"
	ParamLatency            = "latency"
	ParamBannedTime         = "banned"
	ParamIsMarkToken        = "isMarkToken"
	ParamEmailData          = "data"
	ParamEmailCmdType       = "cmd_type"
	ParamEmailParamStr      = "param_str"
	ParamEmailSubject       = "subject"
	ParamEmailValue         = "email"
	ParamEmailQname         = "qname"
	ParamEmailMessageId     = "message_id"
	ParamEmailSendTimeStamp = "send_timestamp"
	ParamExtraParam         = "extra_param"
	ParamPackageName        = "PackageName"
	ParamRedisKey           = "RedisKey"
	ParamReferer            = "referer"
	ParamServer             = "server"
	ParamTaskName           = "task_name"
)

// log type label
const (
	LabelPower       = "power"
	LabelReport      = "report"
	LabelP2p         = "p2p"
	LabelOperation   = "operation"
	LabelAppPush     = "apppush"
	LabelAi          = "ai"
	LabelMonPower    = "monpower"
	LabelStream      = "stream"
	LabelWeb         = "web"
	LabelVideo       = "video"
	LabelAppEvent    = "appevent"
	LabelHubEvent    = "hubevent"
	LableBpItEvent   = "bpit"
	LableCommerce    = "commerce"
	LabelServerEvent = "serverevent"
)

// logging event name
const (
	NameDskSetting       = "dsk_setting"
	NameAutoSignIn       = "auto_sign_in"
	NameAuthority        = "authority"
	NameUnAuthority      = "Unauthorized"
	NameLoginUnAuthority = "LoginUnauthorized"
	NameEmail            = "email"
	NameMonitoring       = "monitoring"
	NameStripe           = "stripe"
	NameDskUtils         = "dskutils"
	NameEiotCard         = "EiotCard"
)

// bucket name
const (
	BucketAppstore = "appstore"
	BucketPublic   = "public"
)

// db name
const (
	DriverMysql         = "mysql"
	DbDefault           = "default"
	DbOta               = "ota"
	DbMonitor           = "monitor"
	DbBoat              = "boat"
	DbChaos             = "chaos"
	DbAppStore          = "appstore"
	DbDefaultReadonly01 = "default-readonly01"
	DbOtaReadonly01     = "ota-readonly01"
	DB_SECURITY_MONITOR = "monitor"
	DBSmart             = "smart"
	DBMoat              = "moat"
	DBHelp              = "help"
	DBShard01           = "shard01"
	DBShard02           = "shard02"
	US                  = "us"
	EU                  = "eu"
	CN                  = "cn"
	DbDefaultProxy      = "default-proxy"
	DbSecurity          = "security"
	Dbpet               = "pet"
	DbClean             = "clean"
	DbBaby              = "baby"
	DbCare              = "care"
	REGION              = "EU"
	ENVIRONMENT         = "PR"
)

// DBNames .
var DBNames = [...]string{
	DbDefault,
}

// DBList .
var DBList = [...]string{
	DbSecurity,
	DbCare,
	Dbpet,
	DbClean,
	DbBaby,
}

// prefix
const (
	PrefixPackageNo      = "pkg_"
	PrefixOrderNo        = "ord_"
	PrefixSubscriptionNo = "sub_"
)

// operator
const (
	OperatorSemicolon   = ";"
	OperatorDot         = ","
	OperatorAsterisk    = "*"
	OperatorDash        = "/"
	OperatorAt          = "@"
	OperatorHyphen      = "-"
	OperatorUnderline   = "_"
	OperatorSpace       = " "
	OperatorAnd         = "&"
	OperatorPercent     = "%"
	OperatorExclamatory = "!"
	OperatorNewLine     = "\n"
	OperatorSpecial     = "##@@"
	OperatorSpecial1    = "##^^"
	OperatorSpecial2    = "##!!"
	OperatorAndEsc      = "&amp;"
	OperatorLtEsc       = "&lt;"
	OperatorGtEsc       = "&gt;"
	OperatorPoint       = "."
	OperatorQuestion    = "?"
)

// header key
const (
	HeaderAuthUser = "X-Auth-User"
	// 客户端发送的token
	HeaderAuthToken    = "X-Auth-Token"
	HeaderRandomNumber = "X-Random-Number"
	HeaderAppName      = "App_name"
)

// language
const (
	LangEn = "en"
	LangDe = "de"
	LangFr = "fr"
	LangJa = "ja"
	LangZh = "zh"
	LangEs = "es"
	LangIt = "it"
	LangNl = "nl"
	LangAr = "ar"
	LangJp = "jp"
	LangKo = "ko"
	LangVi = "vi"
)

// country
const (
	CountryUs = "US"
)

// DBRealDelete 是否物理删除数据库数据
func DBRealDelete() bool {
	return true
}

// DBReadonlyName 返回只读数据库名称
func DBReadonlyName(name string) string {
	return fmt.Sprintf("%s-readonly01", name)
}

// DBProxyName 返回代理数据库名称
func DBProxyName(name string) string {
	return fmt.Sprintf("%s-proxy01", name)
}

const (

	//DID配置表
	IsCheckConfClose = 0 // 关闭
	IsCheckConfOpen  = 1 // 开启

	//前置订单状态
	DidPrefixOrderDeleted     = 0 // 已删除
	DidPrefixOrderAwaitReview = 1 // 待审核
	DidPrefixOrderReviewed    = 2 // 已审核
	DidPrefixOrderCompleted   = 3 // 已完成（尚云方导入后）
	DidPrefixOrderSettled     = 4 // 已结算

	//订单状态
	//DidOrderDeleted    = 0 // 已删除
	DidOrderUnreviewed = 1 // 待审核
	DidOrderProcessing = 2 // 处理中
	DidOrderCompleted  = 3 // 已完成

	//原始Did信息状态
	DidOriginalOrderDeleted  = 0 // 已删除
	DidOriginalOrderNormal   = 1 // 正常
	DidOriginalOrderImported = 2 // 已导入

	DidOriginalToTotal = 1 // 未导入

	//Did信息状态
	DidStatusDeleted = 0 // 已删除
	DidStatusNormal  = 1 // 正常
	WakeupFlag       = 1 // 已唤醒
	WakeupFlagNot    = 0 // 未唤醒

	//DidTotal总表中的状态
	DidUnimported = 0 // 未导入
	DidImported   = 1 // 已导入

	//当前时间戳
	CurrentTime = "2006-01-02 15:04"

	//批量查询/导入
	ImportSize = 1000
	BatchSize  = 5000
	Offset     = 0
)
